﻿document.domain = "pomoho.com";
Pui.upload = {
    reload: function() {
                Pui.loadScript('http://www.pomoho.com/api/userapi.asmx/UploadLimit?taskFrom=webClient&uid=' + _user.uid + '&isAdd=-1&helper=false&remove=false');
           	window.location.reload();
        },
    init: function() {
        var oChannelID = 0;
        var columnID = 0;
        $('#uploadForm_Channel_Other').click(function() {
            parent.Pui.upload.step1.selectOther();
            $(this).blur()
        });
        $('#Upload_2 .meat .s2 a').click(function() {
            parent.Pui.upload.step2.selectDetail();
            $(this).blur();
            return false
        });
        $('#Upload_2 .meat .s3 a').click(function() {
            Pui.upload.step2.tag();
            $(this).blur();
            return false
        });
        $('#Upload_2 .meat .s4 a').click(function() {
            parent.Pui.upload.step2.album();
            $(this).blur();
            return false
        });
        $('#uploadForm_Submit').click(function() {
            var radioText = $('#Upload_1 .meat .s3 .iRadio[@checked]').parent().text();
            var isOther = $('#Upload_1 .meat .s3 .iRadio[@checked]').parent().parent().attr('class');
            n = checkInput();
            if (n) {
                parent.$('#hid_n').val(n);
                if (isOther != 'other') {
                    cName1 = radioText
                }
                if (parent._is_login) {
                    Pui.upload.unite('GoTo2');
                    start_upload($('#file1').val(), $('#uploadForm_Title').val());
                    if ($('#hid_ver').val() == 'family') {
                        $('#Upload_2 .s4').addClass('none');
                        $('#Upload_2 .s5').addClass('none');
                        parent.$('#Layout_1').height('650px')
                    } else {
                        parent.$('#Layout_1').height('700px')
                    }
                } else {
                    parent.Pui.header_v2.loginfo()
                }
            }
        });
        try {
            Pui.upload.dialog.submit()
        } catch(e) {
            Pui.loadScript('http://pvstat.pomoho.com/stat.aspx?siteid=1&bcode=uploaderror');
            alert("哎呀，出错了！：（\n您的浏览器设置可能不允许使用这个页面中的某些功能，请您检查您的浏览器设置。\n有任何问题请咨询我们的客服(0571-89937112) 。请您谅解！\n这个问题的描述是：" + e.name + ": " + e.message)
        }
    },
    step1: {
        selectOther: function() {
            Pui.upload.dialog.getAbs('#Select_1');
            $('#Select_1').show(10,
            function() {
                $('#Select_1').dialog({
                    overlay: true,
                    bgColor: 'black'
                })
            });
            Pui.upload.dialog.imitSelect()
        }
    },
    step2: {
        selectDetail: function() {
            Pui.upload.dialog.getAbs('#Select_2');
            $('#Select_2').show(10,
            function() {
                $('#Select_2').dialog({
                    overlay: true,
                    bgColor: 'black'
                })
            });
            Pui.upload.dialog.imitSelect()
        },
        album: function() {
            Pui.upload.dialog.getAbs('#CreateAlbum');
            $('#CreateAlbum').show(10,
            function() {
                $('#CreateAlbum').dialog({
                    overlay: true,
                    bgColor: 'black'
                })
            })
        },
        tag: function(tagtxt) {
            d = '';
            val = $('#detailForm_Tag').val();
            if (val != '') d = ',';
            tagtxt = d + tagtxt;
            $('#detailForm_Tag').val(val + tagtxt)
        },
        cancleUpload: function() {
            parent.Pui.upload.dialog.alertDialog('标题标题', '内容内容', '', '');
            if (1 == 1) {
                Pui.upload.unite('GoTo1')
            }
        }
    },
    unite: function(i) {
        if (i == 'GoTo2') {
            $('body').attr('id', 'B-Upload-2');
            $('#Upload_1').addClass('none');
            parent.$('#Animation').attr('id', 'Animation_U');
            parent.$('#Layout_2').addClass('none').attr('id', 'Layout_U');
            $('#Upload_2').removeClass('none');
            parent.$('#Animation_X').attr('id', 'Animation');
            parent.$('#Layout_X').removeClass('none').attr('id', 'Layout_2')
        } else {
            parent.$('body').attr('id', 'B-Upload-1');
            parent.$('#Upload_2').addClass('none');
            parent.parent.$('#Animation').attr('id', 'Animation_X');
            parent.parent.$('#Layout_2').addClass('none').attr('id', 'Layout_X');
            parent.$('#Upload_1').removeClass('none');
            parent.parent.$('#Animation_U').attr('id', 'Animation');
            parent.parent.$('#Layout_U').removeClass('none').attr('id', 'Layout_2')
        }
    },
    dialog: {
        getAbs: function(e) {
            var x, y;
            x = (document.body.clientWidth - parseInt($(e).css('width'))) / 2;
            y = document.documentElement.scrollTop + 180;
            parent.$('.dialog').css({
                left: x + 'px',
                top: y + 'px'
            })
        },
        imitSelect: function() {
            parent.$('.dialog .imitSelect li').hover(function() {
                if ($(this).attr('class') != 'ac s') {
                    $(this).addClass('ac')
                }
            },
            function() {
                if ($(this).attr('class') != 'ac s') {
                    $(this).removeClass('ac')
                }
            }).click(function() {
                $(this).addClass('ac s').siblings().removeClass('ac s')
            })
        },
        getID: function(n) {
            if (n == 1) {
                var columnID_All_1 = parent.$('#Select_1 .imitSelect li.s').attr('id');
                if (columnID_All_1 != '') {
                    cName1 = parent.$('#Select_1 .imitSelect li.s').text();
                    oChannelID = parseInt(columnID_All_1.slice(4));
                    $('#Upload_1 .s3 .other span').text('其他-' + cName1);
                    $('#hid_channelID').val(oChannelID)
                } else {
                    oChannelID = 0
                }
            }
            if (n == 2) {
                var columnID_All_2 = parent.$('#Select_2 .imitSelect li.s').attr('id');
                var cName2 = parent.$('#Select_2 .imitSelect li.s').text();
                if (columnID_All_2 != '') {
                    columnID = parseInt(columnID_All_2.slice(4));
                    $('#Upload_2 .s2 .c span').text(cName1 + ' > ' + cName2).css('margin-right', '10px').next().text('修改频道详细分类')
                } else {
                    columnID = 0
                }
            }
        },
        createAlbum: function() {
            var albumSel = $('#detailForm_Album').html();
            var albumName = parent.$('#dialog_AlbumTitle').val();
            var albumIntro = parent.$('#dialog_AlbumIntro').val();
            if (albumName == '') {
                parent.$('#dialog_AlbumTitle_Error').show().text('请填写专辑名称')
            } else if (albumName.length > 16) {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumTitle_Error').show().text('专辑名称不能超过16个字')
            } else if (albumIntro == '') {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').show().text('请填写专辑简介')
            } else if (albumIntro.length > 32) {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').show().text('专辑简介不能超过32个字')
            } else {
                Pui.loadScript("http://www.pomoho.com/do/interfaces/createuserzl.aspx?userid=" + parent._user.uid + "&zlname=" + albumName + "&zlinfo=" + albumIntro)
            }
        },
        createAlbumCallback: function(zlID) {
            var albumSel = $('#detailForm_Album').html();
            var albumName = parent.$('#dialog_AlbumTitle').val();
            if (zlID == -1) {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').hide();
                parent.$('#dialog_AlbumTitle_Error').show().text('专栏已达到上限')
            } else if (zlID == -2) {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').hide();
                parent.$('#dialog_AlbumTitle_Error').show().text('专栏名字重复')
            } else if (zlID == -3) {
                parent.$('#dialog_AlbumTitle_Error').hide();
                parent.$('#dialog_AlbumIntro_Error').hide();
                parent.$('#dialog_AlbumTitle_Error').show().text('创建专栏失败')
            } else {
                $('#detailForm_Album option').removeAttr('selected').parent().html(albumSel + '<option selected="selected" value="' + zlID + '">' + albumName + '</option>');
                $('#Upload_2 .s4 a').css('margin-left', '10px');
                parent.$('#dialog_AlbumIntro_Error').hide();
                parent.$('#dialog_AlbumTitle').val('');
                parent.$('#dialog_AlbumIntro').val('');
                $('#detailForm_Album').focus();
                parent.$('.dialog').hide();
                parent.Pra.ui.overlay()
            }
        },
        submit: function() {
            parent.$('#Select_1 .dHandle .s1').click(function() {
                Pui.upload.dialog.getID(1)
            });
            parent.$('#Select_2 .dHandle .s1').click(function() {
                Pui.upload.dialog.getID(2)
            });
            parent.$('#CreateAlbum .dHandle .s1').click(function() {
                Pui.upload.dialog.createAlbum();
                $(this).blur()
            })
        },
        close: function() {
            $('.dialog').each(function() {
                $(this).find('.close').click(function() {
                    $('.dialog').hide();
                    Pra.ui.overlay();
                    $(this).blur();
                    return false
                })
            })
        },
        alertDialog: function(title, content, tip, handle, center) {
            Pui.upload.dialog.getAbs('#Alert');
            $('#Alert').show(10,
            function() {
                $('#Alert').dialog({
                    overlay: true,
                    bgColor: 'black'
                })
            }).find('h2').text(title).end().find('.imitP p').text(content).end();
            tip == '' ? $('#Alert .tip').remove() : $('#Alert .tip').html('<em>温馨提示：</em>' + tip);
            handle == '' ? null: $('#Alert .dHandle').html(handle);
            center == '' ? null: $('#Alert .imitP p').css('text-align', center)
        }
    }
};
